/**
 * 
 */
package com.manage.action;

import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;


import com.action.AbstractAction;
import com.manage.cache.SdkconfigManager;
import com.manage.model.Sdkconfig;
import com.util.Util;


public class SdkconfigAction extends AbstractAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private Logger logger;
	
	public SdkconfigAction()
	{
		logger = Logger.getLogger(this.getClass());
	}
	
	public String execute()
	{
		return SUCCESS;
	}

	private Sdkconfig       model;
	private String        type;
	private String  operatorname;
	private String  cmccprovince;
	private String  unicomprovince;
	private String  telecomprovince;
	private String feetype;
	private String appointfee;
	
	public String show()
	{
		int sdkpid = model.getSdkprovidersid();
		model = SdkconfigManager.getInstance().getSdkconfigBySdkprovidersid(sdkpid);
		if (model!=null && model.getId() >= 0)
		{
			type = "update";
		}
		else
		{
			model = new Sdkconfig();
			model.setId(-1);
			model.setSdkprovidersid(sdkpid);
			type = "insert";
		}

		return SUCCESS;
	}
	
	public String save()
	{
		if(type.equals("insert"))
		{
			model.setCreatedate(Util.dateToString(new Date()));
			model.setCreateuser(operator.getName());
		}
		if(operatorname!=null && !operatorname.equals("null")&&!"".equals(operatorname))
		{
			model.setOperator(operatorname.replaceAll(", ", ","));
		}
		if(cmccprovince!=null && !cmccprovince.equals("null")&&!"".equals(cmccprovince))
		{
			model.setCmccprovince(cmccprovince.replaceAll(", ", ","));
		}
		if(unicomprovince!=null && !unicomprovince.equals("null")&&!"".equals(unicomprovince))
		{
			model.setUnicomprovince(unicomprovince.replaceAll(", ", ","));
		}
		if(telecomprovince!=null && !telecomprovince.equals("null")&&!"".equals(telecomprovince))
		{
			model.setTelecomprovince(telecomprovince.replaceAll(", ", ","));
		}
		if(feetype!=null && !feetype.equals("null")&&!"".equals(feetype))
		{
			model.setFeetype(Integer.parseInt(feetype));
		}
		else
		{
			model.setFeetype(0);
		}
		if(appointfee!=null && !appointfee.equals("null")&&!"".equals(appointfee))
		{
			model.setAppointfee(appointfee.replaceAll(", ", ","));
		}
		SdkconfigManager.getInstance().saveSdkProviders(operator, type, model);
		return SUCCESS;
	}

	
	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public Sdkconfig getModel() {
		return model;
	}

	public void setModel(Sdkconfig model) {
		this.model = model;
	}

	public String getOperatorname() {
		return operatorname;
	}

	public void setOperatorname(String operatorname) {
		this.operatorname = operatorname;
	}

	public String getCmccprovince() {
		return cmccprovince;
	}

	public void setCmccprovince(String cmccprovince) {
		this.cmccprovince = cmccprovince;
	}

	public String getUnicomprovince() {
		return unicomprovince;
	}

	public void setUnicomprovince(String unicomprovince) {
		this.unicomprovince = unicomprovince;
	}

	public String getTelecomprovince() {
		return telecomprovince;
	}

	public void setTelecomprovince(String telecomprovince) {
		this.telecomprovince = telecomprovince;
	}

	public String getFeetype() {
		return feetype;
	}

	public void setFeetype(String feetype) {
		this.feetype = feetype;
	}

	public String getAppointfee() {
		return appointfee;
	}

	public void setAppointfee(String appointfee) {
		this.appointfee = appointfee;
	}

	
}
